package com.zenithmind.library.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 图书作者关联视图对象
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Data
@Schema(name = "图书作者关联视图对象", description = "图书作者关联信息的视图对象")
public class BookAuthorVO {

    @Schema(description = "关联ID")
    private String id;

    @Schema(description = "图书ID")
    private String bookId;

    @Schema(description = "图书标题")
    private String bookTitle;

    @Schema(description = "图书ISBN")
    private String bookIsbn;

    @Schema(description = "图书封面")
    private String bookCover;

    @Schema(description = "图书出版日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate bookPublishDate;

    @Schema(description = "作者ID")
    private String authorId;

    @Schema(description = "作者姓名")
    private String authorName;

    @Schema(description = "作者英文名")
    private String authorNameEn;

    @Schema(description = "作者笔名")
    private String authorPenName;

    @Schema(description = "作者头像")
    private String authorAvatar;

    @Schema(description = "作者国籍")
    private String authorNationality;

    @Schema(description = "作者角色")
    private String authorRole;

    @Schema(description = "排序号")
    private Integer sortOrder;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 获取作者显示名称
     */
    public String getAuthorDisplayName() {
        if (authorPenName != null && !authorPenName.trim().isEmpty()) {
            return authorPenName;
        }
        return authorName;
    }

    /**
     * 获取作者角色显示
     */
    public String getAuthorRoleDisplay() {
        if (authorRole != null && !authorRole.trim().isEmpty()) {
            return authorRole;
        }
        return "作者";
    }

    /**
     * 判断是否为主要作者
     */
    public boolean isPrimaryAuthor() {
        return sortOrder != null && sortOrder == 1;
    }

    /**
     * 判断是否为编辑
     */
    public boolean isEditor() {
        return authorRole != null && 
               (authorRole.contains("编") || authorRole.contains("Editor"));
    }

    /**
     * 判断是否为译者
     */
    public boolean isTranslator() {
        return authorRole != null && 
               (authorRole.contains("译") || authorRole.contains("Translator"));
    }
}
